package db.pojo;

import java.util.*;
import java.text.SimpleDateFormat;
import db.ext.SexExt;
@SuppressWarnings("unchecked")
/**
 * sex
 */
public class Sex {
	/**
	 * id
	 */
	public int id;
	/**
	 * name
	 */
	public String name;
	SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	public static SexExt DB = new SexExt(); 
	
	public Sex() {
		super();
	}
	
	public Sex(int id, String name) {
		super();
		this.id = id; 
		this.name = name; 
	}
	
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	} 
	
	public void changeIdWith(int id){
		this.id += id;
	}
	
	public void changeIdWithMin(int id,int min){
		this.id += id;
		this.id = this.id < min ? min : this.id;
	}
	
	public void changeIdWithMax(int id,int max){
		this.id += id;
		this.id = this.id > max ? max : this.id;
	}
	
	public void changeIdWithMaxMin(int id,int max,int min){
		this.id += id;
		this.id = this.id < min ? min : this.id;
		this.id = this.id > max ? max : this.id;
	}	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	} 
	
	
	public Map sexToMap() {
		Map map = new HashMap();
		try {
			map.put("id",this.id);
			map.put("name",this.name);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return map;
	}

	public Sex mapToSex(Map map){
		try {
			int id = Integer.parseInt( map.get("id").toString());
			String name =  map.get("name").toString();
			Sex sex = new Sex(id, name);
			return sex;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	} 
	
	public String toString(){
		return sexToMap().toString();
	}
	
	//方便数据操作	
	public Sex insert(){
		return DB.insert(this);
	}
	public Sex update(){
		return DB.update(this);
	}
	
	public int delete(){
		return DB.delete(this);
	}
	
	
	public List<Student> getFK_Students_SexId(){
		return DB.getFK_Students_SexId(this);
	}
	
}
